package com.googlecode.imanager.client.media;

import java.io.Serializable;

import com.googlecode.imanager.client.Document;
import com.googlecode.imanager.client.io.Path;
import com.googlecode.imanager.client.util.Utils;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public abstract class Image implements Serializable {

    private static final long serialVersionUID = 1L;
    
    public static final Image EMPTY_IMAGE;

    private Document owner;
    private Path path;
    
    private Image(){
        path = new Path("");
    }
    
    public Image(Document owner, Path path) {
        this.owner = owner;
        this.path = path;
        
        if (owner == null) {
            throw new IllegalArgumentException("owner");
        }
        if (path == null) {
            throw new IllegalArgumentException("path");
        }
    }

    public abstract void loadContent();

    public final Document getOwner() {
        return owner;
    }

    public final Path getPath() {
        return path;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this){
            return true;
        }
        if (obj instanceof Image){
            Image i = (Image) obj;
            return Utils.isEquals(path, i.path);
        }
        return false;
    }

    @Override
    public int hashCode() {
        return path.hashCode();
    }

    @Override
    public String toString() {
        return "Image[path=" + path + "]";
    }

    static {
        EMPTY_IMAGE = new Image() {
            
            private static final long serialVersionUID = 1L;

            @Override
            public void loadContent() {
            }

        };
    }
}
